Jetty embedded: How to run the same config as with `mvn jetty:run-exploded`?

Posted by Ondra Žižka on Stack Overflow See other posts from Stack Overflow or by Ondra Žižka
Published on 2010-05-10T11:48:40Z Indexed on 2010/05/10 11:54 UTC
Read the original article Hit count: 264

Filed under:
|
|
|
|

Hi, I'd like to have the same Jetty server configuration, created programatically.

When I run mvn jetty:run-exploded, my app works fine. When I run it from my code, the static content is not loaded. I know that I have to add a static content Servlet, so I tried:

Server server = new Server(8080);
Context ctx = new Context( server, "/", Context.SESSIONS );

DefaultServlet defaultServlet = new DefaultServlet();
ServletHolder defaultSH = new ServletHolder( defaultServlet );
defaultSH.setInitParameter( "resourceBase", "./");
ctx.addServlet( defaultSH, "/img" );
ctx.addServlet( defaultSH, "/css" );
ctx.addServlet( defaultSH, "/js" );

I am assuming that the pwd is in the webapp's "root", i.e. where the WEB-INF dir is. This does not work.

Anyway. Is somewhere a clean block of pure Java code which will give me the exact same server config as the mvn jetty:run-explodeds default?

Thanks for help, Ondra

© Stack Overflow or respective owner

Related posts about maven

Related posts about jetty